package peer.gui;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SpringLayout;

import peer.SharingManager.FileReference;

public class LibraryPanel extends JPanel
{
	LibraryModel libraryModel;
	
	public LibraryPanel()
	{
		SpringLayout layout = new SpringLayout();
		setLayout(layout);
		
		libraryModel = new LibraryModel();
		JTable libraryTable = new JTable(libraryModel);
		libraryModel.addTableModelListener(libraryTable);
		JScrollPane libraryScrollPane = new JScrollPane(libraryTable);
		add(libraryScrollPane);
		
		libraryTable.getColumn("Size").setPreferredWidth(8);
		libraryTable.getColumn("Hash code").setPreferredWidth(15);
		
		layout.putConstraint(SpringLayout.WEST, libraryScrollPane, 5, SpringLayout.WEST, this);
		layout.putConstraint(SpringLayout.NORTH, libraryScrollPane, 5, SpringLayout.NORTH, this);
		layout.putConstraint(SpringLayout.EAST, this, 5, SpringLayout.EAST, libraryScrollPane);
		layout.putConstraint(SpringLayout.SOUTH, this, 5, SpringLayout.SOUTH, libraryScrollPane);
	}

	public void addFile(FileReference fr) 
	{
		libraryModel.addFile(fr);
	}
}
